package com.wanxi.controller;

import com.alibaba.fastjson2.JSONObject;
import com.wanxi.dto.ResultDTO;
import com.wanxi.service.ProductTypeService;
import com.wanxi.vo.ProductTypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/productType")
@CrossOrigin(origins = "http://localhost:8081")
public class ProductTypeController {
    @Autowired
    ProductTypeService productTypeService;

    @PutMapping("/add")
    @PreAuthorize("hasAuthority('insertProductType')")
    public ResultDTO addProductType(ProductTypeVO productTypeVO){
        return productTypeService.addProductType(productTypeVO);
    }

    @DeleteMapping("/delete")
    @PreAuthorize("hasAuthority('deleteProductType')")
    public ResultDTO deleteProductType(ProductTypeVO productTypeVO){
        return productTypeService.deleteProductType(productTypeVO);
    }

    @GetMapping("/findAll")
    public ResultDTO findAllProductType(){
        return productTypeService.findAllType();
    }

    @PostMapping("/findById")
    public ResultDTO findProductTypeById(ProductTypeVO productTypeVO){
        return productTypeService.findProductTypeById(productTypeVO);
    }

    @PostMapping("/updateEnable")
    @PreAuthorize("hasAuthority('updateProductType')")
    public ResultDTO updateProductTypeEnable(ProductTypeVO productTypeVO){
        return productTypeService.updateEnable(productTypeVO);
    }

    @PostMapping("/update")
    @PreAuthorize("hasAuthority('updateProductType')")
    public ResultDTO updateProductType(ProductTypeVO productTypeVO){
        return productTypeService.updateProductType(productTypeVO);
    }
}
